iT邦幫忙

2025 iThome 鐵人賽

DAY 2
0
Vue.js

新手學習Vue.js與實作之旅系列 第 2

Day2 建置Vue.js開發環境

  • 分享至 

  • xImage
  •  

昨天對於網頁前端框架有初步的認識,今天的內容將介紹建置Vue.js開發環境的兩種方法哦~首先我們要來安裝非常實用的程式編輯器VS Code以及擴充套件

Visual Studio Code

https://ithelp.ithome.com.tw/upload/images/20250907/201691200AO1OJAuQq.png
官方下載網址 https://code.visualstudio.com/Download

擴充套件

VS Code安裝完成後,在畫面最左手邊的 https://ithelp.ithome.com.tw/upload/images/20250907/20169120E5RaXc2quV.png (Extensions)下載
1. Live Server
提供預覽網頁的功能,也就是將所打的程式碼即時呈現在瀏覽器上。
https://ithelp.ithome.com.tw/upload/images/20250907/20169120kfMC6dx8Rp.png

2. Vue (official)
提供Vue.js 語言可識別的檔案類型,並且具有語法突出顯示、括號匹配和懸停描述等語言功能。
https://ithelp.ithome.com.tw/upload/images/20250907/20169120YeqsfogWmh.png

接下來的內容會介紹撰寫Vue的前置作業哦~

方法一 (使用CDN導入)

從 CDN 引入 Vue 不需要額外的建置流程,只要在 HTML 檔案的 <head>標籤內加入以下語法,就能開始撰寫 Vue 程式碼,這種方式適合快速入門、撰寫基礎範例,但無法使用單一檔案元件 (SFC) 語法,也不適合應用在大型專案。

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

方法二 (安裝Node.js和npm)

透過安裝 Node.js 與 npm,我們可以使用 Vite 建立一個基於 Vue 的單頁應用程式,並支援 Vue 的單一檔案元件 (SFC) 語法,這樣的開發方式不僅適合大型專案與團隊合作,也更能完整地體驗 Vue 的功能與優勢。以下是安裝的步驟流程:

  1. 安裝Node.js
    https://ithelp.ithome.com.tw/upload/images/20250907/20169120efBpYRIIoG.png
    官方下載網址 https://nodejs.org/zh-tw/download

  2. 打開cmd 輸入node -v 和 npm -v 查看版本(檢查是否有安裝成功)
    https://ithelp.ithome.com.tw/upload/images/20250907/20169120n5TJHPN7Z5.png

  3. 將路徑切換到桌面
    https://ithelp.ithome.com.tw/upload/images/20250907/201691200qfChw9rcB.png

  4. 輸入npm init vue@latest表示建立一個新的Vue專案,接著輸入y表示繼續後面的程序,輸入自訂的專案名稱,之後根據需求選擇項目,最後桌面會出現新建的檔案夾
    https://ithelp.ithome.com.tw/upload/images/20250907/20169120jpTfrPLH2a.png
    https://ithelp.ithome.com.tw/upload/images/20250907/20169120yXLegY5SwF.png

  5. 依序輸入上圖的綠色字指令(cd自訂的專案名稱、npm install、npm run dev),之後就會跳出以下畫面
    https://ithelp.ithome.com.tw/upload/images/20250907/20169120CJrAAWDVby.png

  6. 按下ctrl鍵點選上圖中的Local網址,就會出現成功創建的畫面
    https://ithelp.ithome.com.tw/upload/images/20250907/201691208h0rQsbPRb.png

  7. 在VS Code開啟剛才新建的檔案夾,就會看到vue的專案結構了哦
    https://ithelp.ithome.com.tw/upload/images/20250907/20169120V2EplJKc8O.png

參考資源
https://vuejs.org/guide/quick-start.html
https://www.w3schools.com/vue/vue_intro.php
https://code.visualstudio.com/docs/nodejs/vuejs-tutorial
https://www.youtube.com/watch?v=I_xLMmNeLDY


上一篇
Day1 踏入框架的世界
下一篇
Day3 Vue專案結構 + 基礎概念
系列文
新手學習Vue.js與實作之旅4
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言